<template>
  <div class="list-page-container">
    <a-card>
      <a-form layout="inline" @keyup.enter.native="handleSearch">
        <a-row :gutter="24">
          <a-col :md="8" :sm="24">
            <CompositeSearch
              :fieldList="fieldList"
              @getParams="getSearchValue"
              @adSearch="onAdSearch"
              @adClear="onAdClear"
              @tagClick="onTagClick">
              <template v-slot:ad-search-content>
                <a-form-model
                  ref="adSearchFormRef"
                  :model="adSearchFormData"
                  layout="vertical">
                  <a-row :gutter="24">
                    <a-col :span="24">
                      <a-form-model-item label="创建时间">
                        <a-range-picker
                          v-model="createTime"
                          format="YYYY-MM-DD"
                          style="width:100%;"
                          @change="(timeRange, timeStringRange) => setTimeRange('createTimeStart', 'createTimeEnd', timeRange, timeStringRange)"/>
                      </a-form-model-item>
                    </a-col>
                  </a-row>
                </a-form-model>
              </template>
            </CompositeSearch>
          </a-col>
          <a-col :md="16" :sm="24">
            <div class="space-btn">
              <a-button type="primary" icon="plus" @click="onAdd">添加</a-button>
              <a-button @click="onExport">导出</a-button>
              <a-button @click="onBatchOC('批量启用')">批量启用</a-button>
              <a-button @click="onBatchOC('批量关闭')">批量关闭</a-button>
            </div>
          </a-col>
        </a-row>
      </a-form>
      <a-table
        ref="table"
        rowKey="id"
        size="middle"
        bordered
        :loading="loading"
        :columns="columns"
        :dataSource="dataSource"
        :row-selection="{ fixed: true, selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        :scroll="{ x: 1 }"
        :pagination="pagination"
        @change="tableChange">
        <span slot="date" slot-scope="text">{{ text | DateFormat }}</span>
        <template slot="isUse" slot-scope="text, record">
          <a-switch v-model="record.isUse" />
        </template>
        <template slot="isSE" slot-scope="text"><span>{{ isEnum[text] || '' }}</span></template>
        <template slot="action" slot-scope="text, record">
          <span class="cus-text" pointer @click="onCheck(record)">查看</span>
          <span class="cus-text" pointer danger @click="onDelete(record)">删除</span>
        </template>
      </a-table>
    </a-card>
    <!-- 供应商风险控制详情 -->
    <RiskControlDetail ref="RiskControlDetail" />
  </div>
</template>

<script>
import ListPageMixin from '@/mixins/ListPageMixin.js';
import optionsMixin from '@views/supplier-manage/risk-control/optionsMixin.js';
import RiskControlDetail from '@views/supplier-manage/risk-control/detail/index.vue'

export default {
  name: 'RiskControlIndex',
  mixins: [ ListPageMixin, optionsMixin ],
  components: {
    RiskControlDetail
  },
  data() {
    return {
      searchTabList: [],
      adSearchFormData: {
        createTimeStart: '',
        createTimeEnd: '',
      },
      createTime: [],
      dataSource: [],
      originalDataSource: [
        {
          isUse: true,
          pushTime: '5',
          riskMonitoringModel: '供应商全部监控模型 V1.0',
          monitoringRange: '【全部】全部维度',
          timeRange: '2024.01.01 - 2024.06.01',
          monitoringSupplier: '河南盛世机械工具集团有限公司、广州三五零配件有限公司、广汽集团广天有限公司',
          riskMonitoringModelCode: 'FXJK202406001',
          createPerson: '杨先生',
          createTime: '2023-05-01',
          updateTime: '2024-06-08 11:08:30',
        },
        {
          isUse: true,
          pushTime: '4',
          riskMonitoringModel: '供应商综合监控模型 V1.0',
          monitoringRange: '【严重事件】经营范围变更、负责人变更、隶属关系变更、失信信息、重大违法税收【重大事件】司法拍卖、股权出质【关注事项】地址变更、行政处罚、立案信息【提示事项】专利信息、著作权、对外投资',
          timeRange: '2024.01.01 - 2024.06.01',
          monitoringSupplier: '河南盛世机械工具集团有限公司、广州三五零配件有限公司、广汽集团广天有限公司',
          riskMonitoringModelCode: 'FXJK202406001',
          createPerson: '杨先生',
          createTime: '2023-05-01',
          updateTime: '2024-06-08 11:08:30',
        },
        {
          isUse: true,
          pushTime: '3',
          riskMonitoringModel: '严重事件监控模型 V1.0',
          monitoringRange: '【严重事件】经营范围变更、负责人变更、隶属关系变更、失信信息、重大违法税收',
          timeRange: '2024.01.01 - 2024.06.01',
          monitoringSupplier: '河南盛世机械工具集团有限公司、广州三五零配件有限公司、广汽集团广天有限公司',
          riskMonitoringModelCode: 'FXJK202406001',
          createPerson: '杨先生',
          createTime: '2023-05-01',
          updateTime: '2024-06-08 11:08:30',
        },
        {
          isUse: true,
          pushTime: '2',
          riskMonitoringModel: '重大事件监控模型 V1.0',
          monitoringRange: '【重大事件】司法拍卖、股权出质',
          timeRange: '2024.01.01 - 2024.06.01',
          monitoringSupplier: '河南盛世机械工具集团有限公司、广州三五零配件有限公司、广汽集团广天有限公司',
          riskMonitoringModelCode: 'FXJK202406001',
          createPerson: '杨先生',
          createTime: '2023-05-01',
          updateTime: '2024-06-08 11:08:30',
        },
        {
          isUse: true,
          pushTime: '1',
          riskMonitoringModel: '关注事件监控模型 V1.0',
          monitoringRange: '【关注事项】地址变更、行政处罚、立案信息',
          timeRange: '2024.01.01 - 2024.06.01',
          monitoringSupplier: '河南盛世机械工具集团有限公司、广州三五零配件有限公司、广汽集团广天有限公司',
          riskMonitoringModelCode: 'FXJK202406001',
          createPerson: '杨先生',
          createTime: '2023-05-01',
          updateTime: '2024-06-08 11:08:30',
        },
        {
          isUse: true,
          pushTime: '0',
          riskMonitoringModel: '提示事件监控模型 V1.0',
          monitoringRange: '【提示事项】专利信息、著作权、对外投资',
          timeRange: '2024.01.01 - 2024.06.01',
          monitoringSupplier: '河南盛世机械工具集团有限公司、广州三五零配件有限公司、广汽集团广天有限公司',
          riskMonitoringModelCode: 'FXJK202406001',
          createPerson: '杨先生',
          createTime: '2023-05-01',
          updateTime: '2024-06-08 11:08:30',
        },
      ]
    }
  },
  created() {
    this.handleSearch();
  },
  methods: {
    // 获取 搜索框参数
    getSearchValue(currentValue, selectFiledList) {
      console.log(currentValue, selectFiledList, 'getSearchValue');
      this.handleSearch();
    },
    // 确定搜索 高级搜索
    onAdSearch() {
      console.log(this.adSearchFormData, '确定搜索 高级搜索');
      this.handleSearch();
    },
    // 重置 高级搜索
    onAdClear() {
      console.log('重置 高级搜索');
    },
    onTagClick(data) {
      console.log(data, 'onTagClick');
      const { name } = data;
      if (['筛选组合01', '筛选组合02', '筛选组合03'].includes(name)) {
        this.adSearchFormData.supplierStatus = '1';
        this.adSearchFormData.approveStatus = '1';
      } else if (['筛选组合04', '筛选组合05', '筛选组合06'].includes(name)) {
        this.adSearchFormData.supplierStatus = '2';
        this.adSearchFormData.approveStatus = '2';
      } else {
        this.adSearchFormData.supplierStatus = '3';
        this.adSearchFormData.approveStatus = '3';
      }
    },
    handleSearch() {
      this.loading = true;
      setTimeout(() => {
        this.loading = false;
        this.onSelectClear();
        this.dataSource = this.originalDataSource
      }, 100)
    },
    onAdd() {
      this.$refs.RiskControlDetail.open({ isLook: false });
    },
    onExport() {},
    onCheck(record) {
      this.$refs.RiskControlDetail.open({ isLook: true });
    },
    onDelete(record) {
      this.$confirm({
        title: '删除',
        content: '确认删除？',
        okText: '确认',
        cancelText: '取消',
        onOk: () => {
          this.handleSearch();
          this.$message.success(`操作成功`);
        }
      });
    },
    onBatchOC(type) {
      if (this.selectedRowKeys.length) {
        this.$confirm({
          title: `${type}`,
          content: `确认${type}？`,
          okText: '确认',
          cancelText: '取消',
          onOk: () => {
            this.dataSource.forEach((item, index) => {
              if (this.selectedRowKeys.includes(index)) {
                if (type === '批量启用') item.isUse = true
                if (type === '批量关闭') item.isUse = false
              }
            });
            this.handleSearch();
            this.$message.success(`操作成功`);
          }
        });
      } else {
        this.$message.error(`请选择数据！`);
      }
    },
  }
}
</script>

<style lang="less" scoped>
</style>